package com.wzp.fulfill.domain.model.warehouse;

import com.wzp.fulfill.domain.model.fulfillorder.FulfillOrder;
import com.wzp.fulfill.domain.model.fulfillorder.FulfillOrderItem;
import com.wzp.fulfill.domain.gateway.WarehouseApiGateway;

import java.util.List;

/**
 * 代表了一个仓库的领域模型
 */
public class Warehouse {

    private Long warehouseId;

    private WarehouseApiGateway warehouseGateway;

    /**
     * 库存是否充足
     */
    public Boolean isInventoryEnough(List<FulfillOrderItem> fulfillOrderItems) {
        return true;
    }

    /**
     * 库存锁定
     */
    public Boolean lockInventory(FulfillOrder fulfillOrder) {
        return warehouseGateway.lockInventory(
                warehouseId,
                fulfillOrder.getOrderId().getId(),
                fulfillOrder.getSkuCodes(),
                fulfillOrder.getPurchaseCounts());
    }

    public void setWarehouseGateway(WarehouseApiGateway warehouseGateway) {
        this.warehouseGateway = warehouseGateway;
    }
}
